local scene = director:createScene()
function scene:setUp(event)

    dbg.print("sceneGame:setUp")
	
	if (gameStats == "new") then

		local newScale = 320/director.displayWidth
		local newScaleY = 480/director.displayHeight
		
	-------- creating background images

		local colorAvenue = {67, 67, 67}
		
		local spaceA = director:createRectangle( { x=0, y=0, w=30/newScale, h=director.displayHeight, color=color.orange, zOrder = -1 } )
		local lineA = director:createLines( {x=0, y=0, strokeColor=color.black, coords={30/newScale,0, 30/newScale,director.displayHeight},} )
		local spaceB = director:createRectangle( { x=30/newScale, y=0, w=90/newScale, h=director.displayHeight, color=colorAvenue, zOrder = -1 } )
		local lineB = director:createLines( {x=0, y=0, strokeColor=color.black, coords={120/newScale,0, 120/newScale,director.displayHeight},} )	
		local spaceC = director:createRectangle( { x=120/newScale, y=0, w=50/newScale, h=director.displayHeight, color=color.orange, zOrder = -1 } )
		local lineC = director:createLines( {x=0, y=0, strokeColor=color.black, coords={170/newScale,0, 170/newScale,director.displayHeight},} )	
		local spaceD = director:createRectangle( { x=170/newScale, y=0, w=90/newScale, h=director.displayHeight, color=colorAvenue, zOrder = -1 } )
		local lineD = director:createLines( {x=0, y=0, strokeColor=color.black, coords={260/newScale,0, 260/newScale,director.displayHeight},} )	
		local spaceE = director:createRectangle( { x=260/newScale, y=0, w=60/newScale, h=director.displayHeight, color=color.orange, zOrder = -1 } )
		
		local firstLine = 0/newScaleY
		local WidthAvenue = 40/newScale
		for i = 1, 5 do
		local line1 = director:createLines( {x=0, y=0, strokeColor=color.white, coords={60/newScale, firstLine, 60/newScale, firstLine-WidthAvenue},} )	
		local line1 = director:createLines( {x=0, y=0, strokeColor=color.white, coords={90/newScale, firstLine, 90/newScale, firstLine+WidthAvenue},} )	
		local line1 = director:createLines( {x=0, y=0, strokeColor=color.white, coords={200/newScale, firstLine, 200/newScale, firstLine-WidthAvenue},} )	
		local line1 = director:createLines( {x=0, y=0, strokeColor=color.white, coords={230/newScale, firstLine, 230/newScale, firstLine+WidthAvenue},} )	
		firstLine = firstLine + 120/newScaleY
		end
		
		local yTruckOneA = 500/newScaleY;
			truckOneA = director:createSprite(30/newScale, yTruckOneA, "img/truckOrange.png")
			truckOneA.xAnchor=0; truckOneA.yAnchor=0
			truckOneA.xScale=.5/newScale
			truckOneA.yScale=.5/newScaleY
			truckOneA.zOrder=1
		local yTruckOneB = 260/newScaleY;
			truckOneB = director:createSprite(30/newScale, yTruckOneB, "img/vanRed.png")
			truckOneB.xAnchor=0; truckOneB.yAnchor=0
			truckOneB.xScale=.5/newScale
			truckOneB.yScale=.5/newScaleY
			truckOneB.zOrder=1
		local yTruckTwoA = 400/newScaleY;
			truckTwoA = director:createSprite(60/newScale, yTruckTwoA, "img/truckGreen.png")
			truckTwoA.xAnchor=0; truckTwoA.yAnchor=0
			truckTwoA.xScale=.5/newScale
			truckTwoA.yScale=.5/newScaleY
			truckTwoA.zOrder=1
		local yTruckTwoB = 160/newScaleY;
			truckTwoB = director:createSprite(60/newScale, yTruckTwoB, "img/vanBlue.png")
			truckTwoB.xAnchor=0; truckTwoB.yAnchor=0
			truckTwoB.xScale=.5/newScale
			truckTwoB.yScale=.5/newScaleY
			truckTwoB.zOrder=1
		local yTruckThreeA = 300/newScaleY
			truckThreeA = director:createSprite(90/newScale, yTruckThreeA, "img/vanYellow.png")
			truckThreeA.xAnchor=0; truckThreeA.yAnchor=0
			truckThreeA.xScale=.5/newScale
			truckThreeA.yScale=.5/newScaleY
			truckThreeA.zOrder=1
		local yTruckThreeB = 60/newScaleY
			truckThreeB = director:createSprite(90/newScale, yTruckThreeB, "img/vanGreen.png")
			truckThreeB.xAnchor=0; truckThreeB.yAnchor=0
			truckThreeB.xScale=.5/newScale
			truckThreeB.yScale=.5/newScaleY
			truckThreeB.zOrder=1
		local yTruckFourA = -100/newScaleY
			truckFourA = director:createSprite(170/newScale, yTruckFourA, "img/vanRed.png")
			truckFourA.xAnchor=1; truckFourA.yAnchor=1
			truckFourA.xScale=.5/newScale
			truckFourA.yScale=.5/newScaleY
			truckFourA.rotation=180
			truckFourA.zOrder=1
		local yTruckFourB = 240/newScaleY
			truckFourB = director:createSprite(170/newScale, yTruckFourB, "img/vanBlue.png")
			truckFourB.xAnchor=1; truckFourB.yAnchor=1
			truckFourB.xScale=.5/newScale
			truckFourB.yScale=.5/newScaleY
			truckFourB.rotation=180
			truckFourB.zOrder=1
		local yTruckFiveA = 100/newScaleY
			truckFiveA = director:createSprite(200/newScale, yTruckFiveA, "img/truckRed.png")
			truckFiveA.xAnchor=1; truckFiveA.yAnchor=1
			truckFiveA.xScale=.5/newScale
			truckFiveA.yScale=.5/newScaleY
			truckFiveA.rotation=180
			truckFiveA.zOrder=1
		local yTruckFiveB = 340/newScaleY
			truckFiveB = director:createSprite(200/newScale, yTruckFiveB, "img/vanYellow.png")
			truckFiveB.xAnchor=1; truckFiveB.yAnchor=1
			truckFiveB.xScale=.5/newScale
			truckFiveB.yScale=.5/newScaleY
			truckFiveB.rotation=180
			truckFiveB.zOrder=1
		local yTruckSixA = 300/newScaleY
			truckSixA = director:createSprite(230/newScale, yTruckSixA, "img/truckCyan.png")
			truckSixA.xAnchor=1; truckSixA.yAnchor=1
			truckSixA.xScale=.5/newScale
			truckSixA.yScale=.5/newScaleY
			truckSixA.rotation=180
			truckSixA.zOrder=1
		local yTruckSixB = 60/newScaleY
			truckSixB = director:createSprite(230/newScale, yTruckSixB, "img/vanGreen.png")
			truckSixB.xAnchor=1; truckSixB.yAnchor=1
			truckSixB.xScale=.5/newScale
			truckSixB.yScale=.5/newScaleY
			truckSixB.rotation=180
			truckSixB.zOrder=1
		
		local person = director:createSprite(10/newScale, 200/newScaleY, "img/person.png")
			person.xAnchor=0.5; person.yAnchor=.6
			person.xScale=.5/newScale
			person.yScale=.5/newScaleY
			person.rotation=90
			person.zOrder=2
		local buttonRestart = director:createSprite(250/newScale, -50/newScaleY, "img/buttonRestart.png")
			buttonRestart.xAnchor=0.5; buttonRestart.yAnchor=0.5
			buttonRestart.xScale=.6/newScale; buttonRestart.yScale=.5/newScaleY; 
			buttonRestart.zOrder = 6
			buttonRestart.isVisible = false
		local scoreRectangle = director:createRectangle( { x=60/newScale, y=140/newScaleY, w=200/newScale, h=230/newScaleY, color=color.cyan, zOrder = 4 } )
			scoreRectangle.strokeColor=color.black
			scoreRectangle.isVisible = false
		local scoreWin = director:createLabel(160/newScale, 290/newScaleY, "¡YOU WIN!")
			scoreWin.zOrder = 5
			scoreWin.xScale = 1/newScale
			scoreWin.yScale = 1/newScaleY
			scoreWin.hAlignment="center"
			scoreWin.xAnchor=0.5;
			scoreWin.color = color.blue
			scoreWin.isVisible = false
		local scoreTitle = director:createLabel(scoreWin.x, scoreWin.y-60/newScaleY, "Your Time is:")
			scoreTitle.zOrder = 5
			scoreTitle.xScale = 1/newScale
			scoreTitle.yScale = 1/newScaleY
			scoreTitle.hAlignment="center"
			scoreTitle.xAnchor=0.5;
			scoreTitle.color = color.blue
			scoreTitle.isVisible = false
		local scoreText = director:createLabel(scoreWin.x, scoreWin.y-110/newScaleY, "")
			scoreText.text = scoreTime
			scoreText.zOrder = 5
			scoreText.xScale = 1/newScale
			scoreText.yScale = 1/newScaleY
			scoreText.hAlignment="center"
			scoreText.xAnchor=0.5;
			scoreText.color = color.blue
			scoreText.isVisible = false
		local personOne = director:createSprite(290/newScale, 350/newScaleY, "img/person.png")
			personOne.xAnchor=0.5; personOne.yAnchor=.4
			personOne.xScale=.5/newScale
			personOne.yScale=.5/newScaleY
			personOne.rotation=180
			personOne.isVisible = false
		local personTwo = director:createSprite(290/newScale, 280/newScaleY, "img/person.png")
			personTwo.xAnchor=0.5; personTwo.yAnchor=.4
			personTwo.xScale=.5/newScale
			personTwo.yScale=.5/newScaleY
			personTwo.rotation=180
			personTwo.isVisible = false
			
		local isTouching = false;
		local x = 10/newScale;
		local y = 200/newScaleY;
		math.randomseed (os.time ())
		
		if (selectGame == "jump") then
			speedOne = math.random(6, 10)/10/newScaleY
			speedTwo = speedOne+.4/newScaleY
			speedThree = speedOne+.8/newScaleY
			speedFour = speedOne+.1/newScaleY
			speedFive = speedOne+.5/newScaleY
			speedSix = speedOne+.9/newScaleY
		elseif (selectGame == "evade") then
			speedOne = math.random(10, 14)/10/newScaleY
			speedTwo = speedOne+.4/newScaleY
			speedThree = speedOne+.8/newScaleY
			speedFour = speedOne+.1/newScaleY
			speedFive = speedOne+.5/newScaleY
			speedSix = speedOne+.9/newScaleY
		end
			
		local spawnTime = 0;
		local personsNumber = 3;
		local scoreTime = 0;
		system.debugTime = nil
		system.gameTime = 0
		system.timers = {}
		localTime = 0

		local timeTitle = director:createLabel(50/newScale, 450/newScaleY, "Time:")
		timeTitle.zOrder = 2
		timeTitle.xScale = 1/newScale
		timeTitle.yScale = 1/newScaleY
			
		local timeLabel = director:createLabel(120/newScale, 450/newScaleY, "")
		timeLabel.zOrder = 2
		timeLabel.xScale = 1/newScale
		timeLabel.yScale = 1/newScaleY
		
		local personsTitle = director:createLabel(180/newScale, 450/newScaleY, "Persons:")
		personsTitle.zOrder = 2
		personsTitle.xScale = 1/newScale
		personsTitle.yScale = 1/newScaleY
		
		local personsLabel = director:createLabel(290/newScale, 450/newScaleY, "")
		personsLabel.zOrder = 2
		personsLabel.xScale = 1/newScale
		personsLabel.yScale = 1/newScaleY
		
		local pauseRectangle = director:createRectangle( { x=50/newScale, y=80/newScaleY, w=220/newScale, h=300/newScaleY, color=color.black, zOrder = 6 } )
		pauseRectangle.strokeColor=color.black
		pauseRectangle.isVisible = false
		
		local pauseLabel = director:createLabel(110/newScale, 340/newScaleY, "PAUSE")
		pauseLabel.zOrder = 6
		pauseLabel.xScale = 1.5/newScale
		pauseLabel.yScale = 1.5/newScaleY
		pauseLabel.color = color.white
		pauseLabel.isVisible = false
		
		local buttonBackMenu = director:createSprite(-100/newScale, -100/newScaleY, "img/buttonBackMenu.png")
		buttonBackMenu.xAnchor=0.5; buttonBackMenu.yAnchor=0.5
		buttonBackMenu.xScale=.6/newScale; buttonBackMenu.yScale=.5/newScaleY; 
		buttonBackMenu.zOrder = 6
		buttonBackMenu.isVisible = false
		
		local buttonReturn = director:createSprite(-100/newScale, -100/newScaleY, "img/buttonReturn.png")
		buttonReturn.xAnchor=0.5; buttonReturn.yAnchor=0.5
		buttonReturn.xScale=.6/newScale; buttonReturn.yScale=.5/newScaleY; 
		buttonReturn.zOrder = 6
		buttonReturn.isVisible = false
			
		local buttonQuit = director:createSprite(-100/newScale, -100/newScaleY, "img/buttonQuit.png")
		buttonQuit.xAnchor=0.5; buttonQuit.yAnchor=0.5
		buttonQuit.xScale=.6/newScale; buttonQuit.yScale=.5/newScaleY; 
		buttonQuit.zOrder = 6
		buttonQuit.isVisible = false
			
		gameStats = "run"

		local move = function()
		
			if (gameStats == "pause") then
				pauseRectangle.isVisible = true
				pauseLabel.isVisible = true
				buttonRestart.y = 130/newScaleY
				buttonRestart.x = 160/newScale
				buttonRestart.isVisible = true
				buttonReturn.y = 230/newScaleY
				buttonReturn.x = 160/newScale
				buttonReturn.isVisible = true
				buttonBackMenu.y = 280/newScaleY
				buttonBackMenu.x = 160/newScale
				buttonBackMenu.isVisible = true
				buttonQuit.y = 180/newScaleY
				buttonQuit.x = 160/newScale
				buttonQuit.isVisible = true
								
				function buttonBackMenu:touch(event)
					if (event.phase == 'began') then
						system:sendEvent("moveToSceneMenu")
					end
				end	
				buttonBackMenu:addEventListener('touch', buttonBackMenu)
				
				function buttonReturn:touch(event)
					if (event.phase == 'began') then
						system.gameTime = localTime
						gameStats = "continue"
					end
				end
				buttonReturn:addEventListener('touch', buttonReturn)
				
				function buttonQuit:touch(event)
					if (event.phase == 'began') then
						system:quit()
					end
				end
				buttonQuit:addEventListener('touch', buttonQuit)
				
				elseif (gameStats == "continue") then
				pauseRectangle.isVisible = false
				pauseLabel.isVisible = false
				buttonRestart.y = -100/newScale
				buttonRestart.x = -100/newScale
				buttonRestart.isVisible = false
				buttonReturn.y = -100/newScale
				buttonReturn.x = -100/newScale
				buttonReturn.isVisible = false
				buttonQuit.y = -100/newScale
				buttonQuit.x = -100/newScale
				buttonQuit.isVisible = false
				buttonBackMenu.y = -100/newScale
				buttonBackMenu.x = -100/newScale
				buttonBackMenu.isVisible = false
				gameStats = "run"
				elseif (gameStats == "changeGame") then
					if (selectGame == "jump") then
						speedOne = math.random(6, 10)/10/newScaleY
						speedTwo = speedOne+.4/newScaleY
						speedThree = speedOne+.8/newScaleY
						speedFour = speedOne+.1/newScaleY
						speedFive = speedOne+.5/newScaleY
						speedSix = speedOne+.9/newScaleY
					elseif (selectGame == "evade") then
						speedOne = math.random(10, 14)/10/newScaleY
						speedTwo = speedOne+.4/newScaleY
						speedThree = speedOne+.8/newScaleY
						speedFour = speedOne+.1/newScaleY
						speedFive = speedOne+.5/newScaleY
						speedSix = speedOne+.9/newScaleY
					end
					person.x = 10/newScale
					person.y = 200/newScaleY
					person.rotation = 90
					person.isVisible = true
					personOne.isVisible = false
					personTwo.isVisible = false
					scoreRectangle.isVisible = false
					scoreTitle.isVisible = false
					scoreWin.isVisible = false
					scoreText.isVisible = false
					spawnTime = 0;
					personsNumber = 3;
					scoreTime = 0;
					system.debugTime = nil
					system.gameTime = 0
					system.timers = {}
					gameStats = "continue"
				else
				timeLabel.text = math.floor(system:getTime())
				scoreTime = math.floor(system:getTime())
				personsLabel.text = personsNumber
				
				if (spawnTime <= 10) then
					isTouching = false
					spawnTime = spawnTime + 1
				end
					
				if (yTruckOneA <= (-100/newScaleY)) then
					yTruckOneA = 480/newScaleY
					else
					yTruckOneA = yTruckOneA - speedOne
					truckOneA.y = yTruckOneA
				end
				
				if (yTruckOneB <= (-100/newScaleY)) then
					yTruckOneB = 480/newScaleY
					else
					yTruckOneB = yTruckOneB - speedOne
					truckOneB.y = yTruckOneB
				end
				
				if (yTruckTwoA <= (-100/newScaleY)) then
					yTruckTwoA = 480/newScaleY
					else
					yTruckTwoA = yTruckTwoA - speedTwo
					truckTwoA.y = yTruckTwoA
				end
						
				if (yTruckTwoB <= (-100/newScaleY)) then
					yTruckTwoB = 480/newScaleY
					else
					yTruckTwoB = yTruckTwoB - speedTwo
					truckTwoB.y = yTruckTwoB
				end
				
				if (yTruckThreeA <= (-100/newScaleY)) then
					yTruckThreeA = 480/newScaleY
					else
					yTruckThreeA = yTruckThreeA - speedThree
					truckThreeA.y = yTruckThreeA
				end
						
				if (yTruckThreeB <= (-100/newScaleY)) then
					yTruckThreeB = 480/newScaleY
					else
					yTruckThreeB = yTruckThreeB - speedThree
					truckThreeB.y = yTruckThreeB
				end
				
				if (yTruckFourA > 480/newScaleY) then
					yTruckFourA = -100/newScaleY
					else
					yTruckFourA = yTruckFourA + speedFour
					truckFourA.y = yTruckFourA
				end
				
				if (yTruckFourB > 480/newScaleY) then
					yTruckFourB = -100/newScaleY
					else
					yTruckFourB = yTruckFourB + speedFour
					truckFourB.y = yTruckFourB
				end

				if (yTruckFiveA > 480/newScaleY) then
					yTruckFiveA = -100/newScaleY
					else
					yTruckFiveA = yTruckFiveA + speedFive
					truckFiveA.y = yTruckFiveA
				end

				if (yTruckFiveB > 480/newScaleY) then
					yTruckFiveB = -100/newScaleY
					else
					yTruckFiveB = yTruckFiveB + speedFive
					truckFiveB.y = yTruckFiveB
				end

				if (yTruckSixA > 480/newScaleY) then
					yTruckSixA = -100/newScaleY
					else
					yTruckSixA = yTruckSixA + speedSix
					truckSixA.y = yTruckSixA
				end
			
				if (yTruckSixB > 480/newScaleY) then
					yTruckSixB = -100/newScaleY
					else
					yTruckSixB = yTruckSixB + speedSix
					truckSixB.y = yTruckSixB
				end
			
				if (isTouching == true) then
				   if (x <= person.x) then 
					 person.x = person.x-1/newScale
					 else 
					 person.x = person.x+1/newScale
				   end
				   if (y <= person.y) then 
					 person.y = person.y-1/newScaleY
						 if (person.rotation < 180) then
							person.rotation = person.rotation+1
						 end
					 else 
					 person.y = person.y+1/newScaleY
						 if (person.rotation > 0) then
							person.rotation = person.rotation-1
						end
				   end
				   angle = math.atan((person.x-x)/(person.y-y))*180/math.pi
				   
				   if (y == person.y) then
						if x > person.x then
							angle = 90
						else 
							angle = 270
						end
				   end
				   
				   if (person.y > y) then
						angle = angle + 180
				   end
				   person.rotation = angle
				end	
					
				if (selectGame == "jump") then
					if (person.x > 30/newScale and person.x < 60/newScale) then
						if (person.y < (yTruckOneA+100/newScaleY) and person.y > (yTruckOneA+10/newScaleY)) then
							person.y = person.y - speedOne
						elseif (person.y < (yTruckOneB+80/newScaleY) and person.y > (yTruckOneB+10/newScaleY)) then
							person.y = person.y - speedOne
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 60/newScale and person.x < 90/newScale) then
						if (person.y < (yTruckTwoA+100/newScaleY) and person.y > (yTruckTwoA+10/newScaleY)) then
							person.y = person.y - speedTwo
						elseif (person.y < (yTruckTwoB+80/newScaleY) and person.y > (yTruckTwoB+10/newScaleY)) then
							person.y = person.y - speedTwo
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end

					if (person.x > 90/newScale and person.x < 120/newScale) then
						if (person.y < (yTruckThreeA+80/newScaleY) and person.y > (yTruckThreeA+10/newScaleY)) then
							person.y = person.y - speedThree
						elseif (person.y < (yTruckThreeB+80/newScaleY) and person.y > (yTruckThreeB+10/newScaleY)) then
							person.y = person.y - speedThree
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 170/newScale and person.x < 200/newScale) then
						if (person.y < (yTruckFourA+70/newScaleY) and person.y > (yTruckFourA)) then
							person.y = person.y + speedFour
						elseif (person.y < (yTruckFourB+70/newScaleY) and person.y > (yTruckFourB)) then
							person.y = person.y + speedFour
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 200/newScale and person.x < 230/newScale) then
						if (person.y < (yTruckFiveA+90/newScaleY) and person.y > (yTruckFiveA)) then
							person.y = person.y + speedFive
						elseif (person.y < (yTruckFiveB+70/newScaleY) and person.y > (yTruckFiveB)) then
							person.y = person.y + speedFive
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end

					if (person.x > 230/newScale and person.x < 260/newScale) then
						if (person.y < (yTruckSixA+90/newScaleY) and person.y > (yTruckSixA)) then
							person.y = person.y + speedSix
						elseif (person.y < (yTruckSixB+70/newScaleY) and person.y > (yTruckSixB)) then
							person.y = person.y + speedSix
						else
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end		
				elseif (selectGame == "evade") then
					if (person.x > 30/newScale and person.x < 60/newScale) then
						if (person.y < (yTruckOneA+100) and person.y > (yTruckOneA-5)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckOneB+80/newScaleY) and person.y > (yTruckOneB-5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 60/newScale and person.x < 90/newScale) then
						if (person.y < (yTruckTwoA+100/newScaleY) and person.y > (yTruckTwoA-5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckTwoB+80/newScaleY) and person.y > (yTruckTwoB-5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end

					if (person.x > 90/newScale and person.x < 120/newScale) then
						if (person.y < (yTruckThreeA+80/newScaleY) and person.y > (yTruckThreeA-5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckThreeB+80/newScaleY) and person.y > (yTruckThreeB-5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 170/newScale and person.x < 200/newScale) then
						if (person.y < (yTruckFourA+70/newScaleY) and person.y > (yTruckFourA+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckFourB+70/newScaleY) and person.y > (yTruckFourB+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end
						
					if (person.x > 200/newScale and person.x < 230/newScale) then
						if (person.y < (yTruckFiveA+90/newScaleY) and person.y > (yTruckFiveA+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckFiveB+70/newScaleY) and person.y > (yTruckFiveB+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end

					if (person.x > 230/newScale and person.x < 260/newScale) then
						if (person.y < (yTruckSixA+90/newScaleY) and person.y > (yTruckSixA+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						elseif (person.y < (yTruckSixB+70/newScaleY) and person.y > (yTruckSixB+5/newScaleY)) then
							personsNumber = -1
							person.x = 290/newScale
							person.y = 210/newScaleY
						end
					end		
				end
				
				if (person.x > 260/newScale) then
					if (personsNumber == 3) then
						person.x = 10/newScale
						person.y = 200/newScaleY
						person.rotation = 90
						personsNumber = personsNumber-1
						personOne.isVisible = true
						speedOne = speedOne + .5/newScaleY
						speedTwo = speedOne+.4/newScaleY
						speedThree = speedOne+.8/newScaleY
						speedFour = speedOne+.1/newScaleY
						speedFive = speedOne+.5/newScaleY
						speedSix = speedOne+.9/newScaleY
						soundOnePerson = audio:playStreamWithLoop("sound/oneperson.mp3", false)
						
					elseif (personsNumber == 2) then
						person.x = 10/newScale
						person.y = 200/newScaleY
						person.rotation = 90
						personsNumber = personsNumber-1
						personTwo.isVisible = true
						speedOne = speedOne+.5/newScaleY
						speedTwo = speedOne+.4/newScaleY
						speedThree = speedOne+.8/newScaleY
						speedFour = speedOne+.1/newScaleY
						speedFive = speedOne+.5/newScaleY
						speedSix = speedOne+.9/newScaleY
						soundOnePerson = audio:playStreamWithLoop("sound/oneperson.mp3", false)
						
					elseif (personsNumber == 1) then
			-------------WIN
						soundWin = audio:playStreamWithLoop("sound/win.mp3", false)
						person.x = 290/newScale
						person.y = 210/newScaleY
						person.rotation = 180
						personsNumber = personsNumber-1
						
						if (selectGame == "jump") then
							local file = io.open("scorejump.txt")
							scoreListJumpOne = tonumber(file:read())
							scoreListJumpTwo = tonumber(file:read())
							scoreListJumpThree = tonumber(file:read())
							file:close()
											
							if (scoreTime < scoreListJumpOne) then
								scoreTitle.text = "GREAT TIME:"
								scoreListJumpThree = scoreListJumpTwo
								scoreListJumpTwo = scoreListJumpOne
								scoreListJumpOne = scoreTime
								elseif (scoreTime < scoreListJumpTwo) then
									scoreTitle.text = "GREAT TIME:"
									scoreListJumpThree = scoreListJumpTwo
									scoreListJumpTwo = scoreTime
										elseif (scoreTime < scoreListJumpThree) then
										scoreTitle.text = "GREAT TIME:"
										scoreListJumpThree = scoreTime
							end
							
							file = io.open("scorejump.txt", "w")
							file:write(scoreListJumpOne.."\n")
							file:write(scoreListJumpTwo.."\n")
							file:write(scoreListJumpThree.."\n")
							file:close()
						end
						 
						if (selectGame == "evade") then
							file = io.open("scoreevade.txt")
							scoreListEvadeOne = tonumber(file:read())
							scoreListEvadeTwo = tonumber(file:read())
							scoreListEvadeThree = tonumber(file:read())
							file:close()
							
							if (scoreTime < scoreListEvadeOne) then
								scoreTitle.text = "GREAT TIME:"
								scoreListEvadeThree = scoreListEvadeTwo
								scoreListEvadeTwo = scoreListEvadeOne
								scoreListEvadeOne = scoreTime
								elseif (scoreTime < scoreListEvadeTwo) then
									scoreTitle.text = "GREAT TIME:"
									scoreListEvadeThree = scoreListEvadeTwo
									scoreListEvadeTwo = scoreTime
										elseif (scoreTime < scoreListEvadeThree) then
										scoreTitle.text = "GREAT TIME:"
										scoreListEvadeThree = scoreTime
							end
							
							file = io.open("scoreevade.txt", "w")
							file:write(scoreListEvadeOne.."\n")
							file:write(scoreListEvadeTwo.."\n")
							file:write(scoreListEvadeThree.."\n")
							file:close()
						end
							buttonRestart.y = 10/newScaleY
							buttonRestart.x = 250/newScale
							buttonRestart.isVisible = true
							scoreRectangle.isVisible = true
							scoreText.text = scoreTime
							scoreText.isVisible = true
							scoreTitle.text = "Your Time is:"
							scoreTitle.isVisible = true
							scoreWin.text = "¡YOU WIN!"
							scoreWin.isVisible = true
							personOne.isVisible = false
							personTwo.isVisible = false
							person.isVisible = false
						elseif (personsNumber == -1) then
			----------------LOSE
							person.x = 290/newScale
							person.y = 210/newScaleY
							person.rotation = 180
							personsNumber = 0
							soundLose = audio:playStreamWithLoop("sound/lose.mp3", false)
							buttonRestart.y = 10/newScaleY
							buttonRestart.x = 250/newScale
							buttonRestart.isVisible = true
							scoreRectangle.isVisible = true
							scoreTitle.text = "Try again"
							scoreTitle.isVisible = true
							scoreWin.text = "¡YOU LOSE!"
							scoreWin.isVisible = true
							personOne.isVisible = false
							personTwo.isVisible = false
							person.isVisible = false
					else
						person.x = 290/newScale
						person.y = 210/newScaleY
						person.rotation = 180
						if (personsNumber == 0) then
							buttonRestart.y = 10/newScaleY
							buttonRestart.x = 250/newScale
							buttonRestart.isVisible = true
						end
					end
				end		
					
				function buttonRestart:touch(event)
					if (event.phase == 'began') then
						if (selectGame == "jump") then
							speedOne = math.random(6, 10)/10/newScaleY
							speedTwo = speedOne+.4/newScaleY
							speedThree = speedOne+.8/newScaleY
							speedFour = speedOne+.1/newScaleY
							speedFive = speedOne+.5/newScaleY
							speedSix = speedOne+.9/newScaleY
						elseif (selectGame == "evade") then
							speedOne = math.random(10, 14)/10/newScaleY
							speedTwo = speedOne+.4/newScaleY
							speedThree = speedOne+.8/newScaleY
							speedFour = speedOne+.1/newScaleY
							speedFive = speedOne+.5/newScaleY
							speedSix = speedOne+.9/newScaleY
						end
						person.x = 10/newScale
						person.y = 200/newScaleY
						person.rotation = 90
						person.isVisible = true
						personOne.isVisible = false
						personTwo.isVisible = false
						scoreRectangle.isVisible = false
						scoreTitle.isVisible = false
						scoreWin.isVisible = false
						scoreText.isVisible = false
						spawnTime = 0;
						personsNumber = 3;
						scoreTime = 0;
						system.debugTime = nil
						system.gameTime = 0
						system.timers = {}
						gameStats = "continue"
					end
				end
				buttonRestart:addEventListener('touch', buttonRestart)			
			end
		end
	 
		local onTouch = function(event)
			if (event.phase == "began") then 
			   isTouching = true
			   x = event.x
			   y = event.y
			end
			if (event.phase == "moved") then
			   x = event.x
			   y = event.y
			end
			if (event.phase == "ended") then 
			   isTouching = false 
			end
		end
		system:addEventListener("update", move)
		system:addEventListener("touch", onTouch)
	end
end

function scene:tearDown(event)
    dbg.print("sceneGame:tearDown")
end
scene:addEventListener({"setUp", "tearDown"}, scene)
return scene -- We must return the scene object!